package org.example.setup.controller;

import org.example.setup.utils.AliyunOSSUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

/**
 * 文件请求处理
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("file")
public class SysFileController
{
    private static final Logger log = LoggerFactory.getLogger(SysFileController.class);

    @Autowired
    private AliyunOSSUtils aliyunOSSUtils;

    /**
     * 文件上传请求
     */
    @PostMapping("file")
    public String upload(MultipartFile file) throws IOException {
        try {
            String s = aliyunOSSUtils.putObject(file.getInputStream(), file.getOriginalFilename());
            return s;
        } catch (IOException e) {
            log.error("文件上传失败：", e);
            return "文件上传失败：" + e.getMessage();
        }
    }
    @GetMapping("file2")
    public String file2(){
        File file = new File("D:\\secFile\\logo.jpg");
        try {
            String s = aliyunOSSUtils.putObject(file);
            return s;
        } catch (Exception e) {
            log.error("文件上传失败：", e);
            return "文件上传失败：" + e.getMessage();
        }
    }
}
